﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.Common;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.Admin.Controllers.Plugin
{
    public class ChainTreeController : ManageController
    {
        public IUsersService bll { get; set; }
        public IActionResult Direct()
        {
            string user_name = CMSRequest.GetQueryString("keywords", HttpContext);
            string strwhere = "where user_id>0";
            var user = bll.GetModel(user_name);
            if (user != null)
            {
                if (user.user_id > 0)
                {
                    strwhere = strwhere + " and layer>=" + user.layer;
                }
            }
            var alllist = bll.GetList(strwhere);
            StringBuilder directs = new StringBuilder();
            directs.Append("{ id:1, pId:0, name:'会员系统：', open: true }");
            foreach (var item in alllist)
            {
                directs.Append(",{ id:" + item.id + ", pId:" + item.pid + ", name:'用户名：" + item.user_name + " 姓名：" + item.nick_name + "' }");
            }
            ViewBag.directs = directs.ToString();
            return View("~/Areas/Admin/Views/Finance/TreeDirect.cshtml");
        }
        public IActionResult Indirect()
        {
            string user_name = CMSRequest.GetQueryString("keywords", HttpContext);
            string strwhere = "where user_id>0";
            var user = bll.GetModel(user_name);
            if (user != null)
            {
                if (user.user_id > 0)
                {
                    strwhere = strwhere + " and layer>=" + user.layer;
                }
            }
            var alllist = bll.GetList(strwhere);
            StringBuilder directs = new StringBuilder();
            directs.Append("{ id:1, pId:0, name:'会员系统：', open: true }");
            foreach (var item in alllist)
            {
                directs.Append(",{ id:" + item.id + ", pId:" + item.iid + ", name:'用户名：" + item.user_name + " 姓名：" + item.nick_name + "' }");
            }
            ViewBag.directs = directs.ToString();
            return View("~/Areas/Admin/Views/Finance/TreeIndirect.cshtml");
        }
        StringBuilder sb1 = new StringBuilder();
        public IActionResult Track()
        {
            string user_name = CMSRequest.GetQueryString("keywords", HttpContext);
            var user = bll.GetModel(user_name);
            if (user == null)
            {
                user_name = "test";
            }
            if (user != null)
            {
                if (user.user_id == 0)
                {
                    user_name = "test";
                }
            }
            ToTable1(user_name);
            ViewBag.sb1 = sb1.ToString();
            return View("~/Areas/Admin/Views/Finance/TreeTrack.cshtml");
        }
        #region Track
        private void ToTable1(string user_name)
        {
            var user = bll.GetModel(user_name);
            if (user != null)
            {
                sb1.AppendLine("<tr class=\"cell1\">");
                sb1.AppendLine("<td colspan = \"8\" style = \"text-align: center; \"> ");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table1\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px; \">");
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + user.user_name + "\" target=\"_self\">" + user.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align = \"center\"> " + user.nick_name + " </td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + user.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(user.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + user.pass_time?.ToShortDateString() + " </td></tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
                sb1.AppendLine("</tr>");
            }
            ToTable2(user_name);
        }
        private void ToTable2(string user_name)
        {
            var user = bll.GetModel(user_name);
            NetCoreCMS.Models.Users luser = null;
            NetCoreCMS.Models.Users ruser = null;
            try
            {
                if (user != null)
                {
                    luser = bll.GetUserByIndirectID(user.user_id, 1);
                    ruser = bll.GetUserByIndirectID(user.user_id, 2);
                }
            }
            catch (Exception)
            {

                throw;
            }
            if (luser != null)
            {
                if (luser.id == 1)
                {
                    luser = null;
                }
            }

            sb1.AppendLine("<tr class=\"cell1\">");

            sb1.AppendLine("<td colspan = \"4\" style=\"text-align: center; \">");
            sb1.AppendLine("<table id = \"ctl00_Content_Body_Table2\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px; \">");
            if (luser != null)
            {
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + luser.user_name + "\" target=\"_self\">" + luser.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + luser.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(luser.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + luser.pass_time?.ToShortDateString() + " </td></tr>");
            }
            else
            {
                sb1.AppendLine("<tr class=\"node_row0\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"../user_edit/index?action=Add&directid=" + user.user_name + "&leftright=1&indirectid=" + user.user_name + "\" target=\"_self\">注册会员</a></td>");
                sb1.AppendLine("</tr>");
            }
            sb1.AppendLine("</table>");
            sb1.AppendLine("</td>");

            sb1.AppendLine("<td colspan = \"4\" style=\"text-align: center; \">");
            sb1.AppendLine("<table id = \"ctl00_Content_Body_Table3\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px; \">");
            if (ruser != null)
            {
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + ruser.user_name + "\" target=\"_self\">" + ruser.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align = \"center\"> " + ruser.nick_name + " </td></tr>");

                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + ruser.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(ruser.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + ruser.pass_time?.ToShortDateString() + " </td></tr>");
            }
            else
            {
                sb1.AppendLine("<tr class=\"node_row0\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"../user_edit/index?action=Add&directid=" + user.user_name + "&leftright=2&indirectid=" + user.user_name + "\" target=\"_self\">注册会员</a></td>");
                sb1.AppendLine("</tr>");
            }
            sb1.AppendLine("</table>");
            sb1.AppendLine("</td>");

            sb1.AppendLine("</tr>");
            ToTable3(luser, ruser);
        }
        private void ToTable3(NetCoreCMS.Models.Users luser, NetCoreCMS.Models.Users ruser)
        {
            NetCoreCMS.Models.Users luser1 = null;
            NetCoreCMS.Models.Users ruser1 = null;
            NetCoreCMS.Models.Users luser2 = null;
            NetCoreCMS.Models.Users ruser2 = null;
            try
            {
                if (luser != null)
                {
                    luser1 = bll.GetUserByIndirectID(luser.user_id, 1);
                    ruser1 = bll.GetUserByIndirectID(luser.user_id, 2);
                }
                if (ruser != null)
                {
                    luser2 = bll.GetUserByIndirectID(ruser.user_id, 1);
                    ruser2 = bll.GetUserByIndirectID(ruser.user_id, 2);
                }
            }
            catch (Exception ex)
            {

            }
            sb1.AppendLine("<tr class=\"cell1\">");
            if (luser1 != null)
            {
                sb1.AppendLine("<td colspan = \"2\" style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table4\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + luser1.user_name + "\" target=\"_self\">" + luser1.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align = \"center\"> " + luser1.nick_name + " </td></tr>");

                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + luser1.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(luser1.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + luser1.pass_time?.ToShortDateString() + " </td></tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else if (luser != null && luser1 == null)
            {
                sb1.AppendLine("<td colspan = \"2\" style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table4\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row0\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"../user_edit/index?action=Add&directid=" + luser.user_name + "&leftright=1&indirectid=" + luser.user_name + "\" target=\"_self\">注册会员</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else
            {
                sb1.AppendLine("<td colspan = \"2\" style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table4\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            if (ruser1 != null)
            {
                sb1.AppendLine("<td colspan = \"2\" style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table5\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + ruser1.user_name + "\" target=\"_self\">" + ruser1.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align = \"center\"> " + ruser1.nick_name + " </td></tr>");

                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + ruser1.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(ruser1.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + ruser1.pass_time?.ToShortDateString() + " </td></tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else if (luser != null && ruser1 == null)
            {
                sb1.AppendLine("<td colspan = \"2\" style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table5\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row0\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"../user_edit/index?action=Add&directid=" + luser.user_name + "&leftright=2&indirectid=" + luser.user_name + "\" target=\"_self\">注册会员</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else
            {
                sb1.AppendLine("<td colspan = \"2\" style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table5\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            if (luser2 != null)
            {
                sb1.AppendLine("<td colspan = \"2\" style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table6\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + luser2.user_name + "\" target=\"_self\">" + luser2.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align = \"center\"> " + luser2.nick_name + " </td></tr>");

                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + luser2.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(luser2.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + luser2.pass_time?.ToShortDateString() + " </td></tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else if (ruser != null && luser2 == null)
            {
                sb1.AppendLine("<td colspan = \"2\" style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table6\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row0\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"../user_edit/index?action=Add&directid=" + ruser.user_name + "&leftright=1&indirectid=" + ruser.user_name + "\" target=\"_self\">注册会员</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else
            {
                sb1.AppendLine("<td colspan = \"2\" style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table6\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            if (ruser2 != null)
            {
                sb1.AppendLine("<td colspan = \"2\" style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table7\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + ruser2.user_name + "\" target=\"_self\">" + ruser2.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align = \"center\"> " + ruser2.nick_name + " </td></tr>");

                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + ruser2.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(ruser2.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + ruser2.pass_time?.ToShortDateString() + " </td></tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else if (ruser != null && ruser2 == null)
            {
                sb1.AppendLine("<td colspan = \"2\" style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table7\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row0\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"../user_edit/index?action=Add&directid=" + ruser.user_name + "&leftright=2&indirectid=" + ruser.user_name + "\" target=\"_self\">注册会员</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else
            {
                sb1.AppendLine("<td colspan = \"2\" style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table7\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }

            sb1.AppendLine("</tr>");
            ToTable4(luser1, ruser1, luser2, ruser2);
        }
        private void ToTable4(NetCoreCMS.Models.Users luser1, NetCoreCMS.Models.Users ruser1, NetCoreCMS.Models.Users luser2, NetCoreCMS.Models.Users ruser2)
        {
            NetCoreCMS.Models.Users luser1_l = null;
            NetCoreCMS.Models.Users luser1_r = null;
            NetCoreCMS.Models.Users ruser1_l = null;
            NetCoreCMS.Models.Users ruser1_r = null;
            NetCoreCMS.Models.Users luser2_l = null;
            NetCoreCMS.Models.Users luser2_r = null;
            NetCoreCMS.Models.Users ruser2_l = null;
            NetCoreCMS.Models.Users ruser2_r = null;
            try
            {
                if (luser1 != null)
                {
                    luser1_l = bll.GetUserByIndirectID(luser1.user_id, 1);
                    luser1_r = bll.GetUserByIndirectID(luser1.user_id, 2);
                }
                if (ruser1 != null)
                {
                    ruser1_l = bll.GetUserByIndirectID(ruser1.user_id, 1);
                    ruser1_r = bll.GetUserByIndirectID(ruser1.user_id, 2);
                }
                if (luser2 != null)
                {
                    luser2_l = bll.GetUserByIndirectID(luser2.user_id, 1);
                    luser2_r = bll.GetUserByIndirectID(luser2.user_id, 2);
                }
                if (ruser2 != null)
                {
                    ruser2_l = bll.GetUserByIndirectID(ruser2.user_id, 1);
                    ruser2_r = bll.GetUserByIndirectID(ruser2.user_id, 2);
                }
            }
            catch (Exception ex)
            {

            }
            sb1.AppendLine("<tr class=\"cell1\">");
            #region luser1
            if (luser1_l != null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table8\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + luser1_l.user_name + "\" target=\"_self\">" + luser1_l.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align = \"center\"> " + luser1_l.nick_name + " </td></tr>");

                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + luser1_l.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(luser1_l.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + luser1_l.pass_time?.ToShortDateString() + " </td></tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else if (luser1 != null && luser1_l == null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table8\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row0\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"../user_edit/index?action=Add&directid=" + luser1.user_name + "&leftright=1&indirectid=" + luser1.user_name + "\" target=\"_self\">注册会员</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table8\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            if (luser1_r != null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table9\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + luser1_r.user_name + "\" target=\"_self\">" + luser1_r.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align = \"center\"> " + luser1_r.nick_name + " </td></tr>");

                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + luser1_r.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(luser1_r.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + luser1_r.pass_time?.ToShortDateString() + " </td></tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else if (luser1 != null && luser1_r == null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table9\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row0\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"../user_edit/index?action=Add&directid=" + luser1.user_name + "&leftright=2&indirectid=" + luser1.user_name + "\" target=\"_self\">注册会员</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table9\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            #endregion
            #region ruser1
            if (ruser1_l != null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table10\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + ruser1_l.user_name + "\" target=\"_self\">" + ruser1_l.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align = \"center\"> " + ruser1_l.nick_name + " </td></tr>");

                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + ruser1_l.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(ruser1_l.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + ruser1_l.pass_time?.ToShortDateString() + " </td></tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else if (ruser1 != null && ruser1_l == null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table10\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row0\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"../user_edit/index?action=Add&directid=" + ruser1.user_name + "&leftright=1&indirectid=" + ruser1.user_name + "\" target=\"_self\">注册会员</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table10\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            if (ruser1_r != null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table11\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + ruser1_r.user_name + "\" target=\"_self\">" + ruser1_r.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align = \"center\"> " + ruser1_r.nick_name + " </td></tr>");

                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + ruser1_r.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(ruser1_r.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + ruser1_r.pass_time?.ToShortDateString() + " </td></tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else if (ruser1 != null && ruser1_r == null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table11\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row0\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"../user_edit/index?action=Add&directid=" + ruser1.user_name + "&leftright=2&indirectid=" + ruser1.user_name + "\" target=\"_self\">注册会员</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table11\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            #endregion
            #region luser2
            if (luser2_l != null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table12\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + luser2_l.user_name + "\" target=\"_self\">" + luser2_l.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align = \"center\"> " + luser2_l.nick_name + " </td></tr>");

                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + luser2_l.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(luser2_l.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + luser2_l.pass_time?.ToShortDateString() + " </td></tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else if (luser2 != null && luser2_l == null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table12\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row0\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"../user_edit/index?action=Add&directid=" + luser2.user_name + "&leftright=1&indirectid=" + luser2.user_name + "\" target=\"_self\">注册会员</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table12\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            if (luser2_r != null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table13\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + luser2_r.user_name + "\" target=\"_self\">" + luser2_r.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align = \"center\"> " + luser2_r.nick_name + " </td></tr>");

                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + luser2_r.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(luser2_r.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + luser2_r.pass_time?.ToShortDateString() + " </td></tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else if (luser2 != null && luser2_r == null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table13\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row0\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"../user_edit/index?action=Add&directid=" + luser2.user_name + "&leftright=2&indirectid=" + luser2.user_name + "\" target=\"_self\">注册会员</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table13\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            #endregion
            #region ruser2
            if (ruser2_l != null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table14\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + ruser2_l.user_name + "\" target=\"_self\">" + ruser2_l.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align = \"center\"> " + ruser2_l.nick_name + " </td></tr>");

                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + ruser2_l.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(ruser2_l.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + ruser2_l.pass_time?.ToShortDateString() + " </td></tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else if (ruser2 != null && ruser2_l == null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table14\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row0\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"../user_edit/index?action=Add&directid=" + ruser2.user_name + "&leftright=1&indirectid=" + ruser2.user_name + "\" target=\"_self\">注册会员</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table14\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            if (ruser2_r != null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table15\" class=\"node1\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row1\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"?keywords=" + ruser2_r.user_name + "\" target=\"_self\">" + ruser2_r.user_name + "</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align = \"center\"> " + ruser2_r.nick_name + " </td></tr>");

                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + ruser2_l.team_users + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\">" + Convert.ToInt64(ruser2_r.team_point) + "</td></tr>");
                sb1.AppendLine("<tr class=\"node_row0\"><td align =\"center\"> " + ruser2_r.pass_time?.ToShortDateString() + " </td></tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else if (ruser2 != null && ruser2_r == null)
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table15\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("<tr class=\"node_row0\">");
                sb1.AppendLine("<td align = \"center\"><a href=\"../user_edit/index?action=Add&directid=" + ruser2.user_name + "&leftright=2&indirectid=" + ruser2.user_name + "\" target=\"_self\">注册会员</a></td>");
                sb1.AppendLine("</tr>");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            else
            {
                sb1.AppendLine("<td style=\"text-align: center;\">");
                sb1.AppendLine("<table id = \"ctl00_Content_Body_Table15\" class=\"node\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\" style=\"border-width:0px;width:100px;\">");
                sb1.AppendLine("</table>");
                sb1.AppendLine("</td>");
            }
            #endregion
            sb1.AppendLine("</tr>");
        }
        #endregion
    }
}